package com.sys.db.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.json.annotations.JSON;

import com.opensymphony.xwork2.ActionSupport;
import com.sys.db.manager.DefFlowManager;
import com.sys.db.manager.RunFlowJobManager;
import com.sys.pojo.DefFlow;

public class DefFlowAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private List list=null;
	private DefFlowManager defFlowManager;
	private RunFlowJobManager runFlowJobManager;
	private DefFlow defFlow;
	private boolean success=true;
	private String message;
	private String datas;
	private String ids;
	private int count;
	private String start;
	private String limit;
	private String flowId;
	private List flowList;
	
	private int count2;
	private String ids2;
	private String datas2;
	/**
	 * 列出所有job
	 * @return
	 */
	public String listFlows(){
		try {
			List listAll=defFlowManager.findAll();
			if(start!=null&&limit!=null){
				list=defFlowManager.findByPage(new Integer(start), new Integer(limit));
				count=listAll.size();
			}else{
				list=listAll;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	/**
	 * 保存页面修改/新增数据
	 */
	public String saveFlows(){
		try {
			defFlowManager.saveOrUpdate(datas);
		} catch (Exception e) {
			success=false;
			message=e.getMessage();
			e.printStackTrace();
		}
		
		return SUCCESS;
	}
	/**
	 * 删除选择的数据
	 */
	public String deleteFlows(){
		try {
			defFlowManager.deleteByIds(ids);
		} catch (Exception e) {
			success=false;
			message=e.getMessage();
			e.printStackTrace();
		}
		
		return SUCCESS;
	}
	/**
	 * 根据作业流ID查出所有作业
	 */
	public String listJobsByFlow(){
		try {
			if(flowId!=null &&flowId!="undefined"&&!"".equals(flowId)){
				flowList=runFlowJobManager.findByFlowId(new Integer(flowId));
			}else{
				flowList=new ArrayList();;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	/**
	 * 保存页面修改/新增数据
	 */
	public String saveFlowJobs(){
		try {
			runFlowJobManager.saveOrUpdate(datas2,flowId);
		} catch (Exception e) {
			success=false;
			message=e.getMessage();
			e.printStackTrace();
		}
		
		return SUCCESS;
	}
	/**
	 * 删除选择的数据
	 */
	public String deleteFlowJobs(){
		try {
			runFlowJobManager.deleteByIds(ids2);
		} catch (Exception e) {
			success=false;
			message=e.getMessage();
			e.printStackTrace();
		}
		
		return SUCCESS;
	}
	
	public List getList() {
		return list;
	}
	public void setList(List list) {
		this.list = list;
	}
	@JSON(serialize=false)
	public DefFlowManager getDefFlowManager() {
		return defFlowManager;
	}
	public void setDefFlowManager(DefFlowManager defFlowManager) {
		this.defFlowManager = defFlowManager;
	}

	@JSON(serialize=false)
	public RunFlowJobManager getRunFlowJobManager() {
		return runFlowJobManager;
	}
	public void setRunFlowJobManager(RunFlowJobManager runFlowJobManager) {
		this.runFlowJobManager = runFlowJobManager;
	}

	public DefFlow getDefFlow() {
		return defFlow;
	}

	public void setDefFlow(DefFlow defFlow) {
		this.defFlow = defFlow;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getDatas() {
		return datas;
	}

	public void setDatas(String datas) {
		this.datas = datas;
	}
	public String getIds() {
		return ids;
	}
	public void setIds(String ids) {
		this.ids = ids;
	}
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	public String getStart() {
		return start;
	}
	public void setStart(String start) {
		this.start = start;
	}
	public String getLimit() {
		return limit;
	}
	public void setLimit(String limit) {
		this.limit = limit;
	}
	public String getFlowId() {
		return flowId;
	}
	public void setFlowId(String flowId) {
		this.flowId = flowId;
	}
	public List getFlowList() {
		return flowList;
	}
	public void setFlowList(List flowList) {
		this.flowList = flowList;
	}
	public int getCount2() {
		return count2;
	}
	public void setCount2(int count2) {
		this.count2 = count2;
	}
	public String getIds2() {
		return ids2;
	}
	public void setIds2(String ids2) {
		this.ids2 = ids2;
	}
	public String getDatas2() {
		return datas2;
	}
	public void setDatas2(String datas2) {
		this.datas2 = datas2;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}

	
}
